<template>
    <div class="fab-container">
        <button class="fab-button" @click="toggleMenu">
            +</button>
        <Transition name="fab-fade" v-if="isMenuOpen">
            <div class="mask" v-if="isMenuOpen"></div>
        </Transition>
        <Transition name="fab-fade">
            <div v-if="isMenuOpen" class="fab-menu">
                <div class="fab-menu-item">
                    <a>用户名:</a>
                    <input type="text" v-model="userName" placeholder="张三" />
                </div>
                <!-- <div class="fab-menu-item">
                <a>密码:</a>
                <input type="text" @blur="handlePasswordInput" placeholder="123456" />
            </div> -->
                <div class="fab-menu-item">
                    <button @click="submitValue">
                        <p>确 认</p>
                    </button>
                </div>
            </div>
        </Transition>
    </div>
</template>
<script setup>
import { ref } from 'vue';
import { useLoginStore } from '@/stores/loginStore';
const loginStore = useLoginStore();
loginStore.actions.loadLogin();
const isLogin = ref(loginStore.state.login.login);
const emit = defineEmits(['submit']);
const isMenuOpen = ref(false);
const userName = ref('');

const toggleMenu = () => {
    isMenuOpen.value = !isMenuOpen.value;
}
const password = ref('');

const handlePasswordInput = (e) => {

    e.target.value = e.target.value.replace(/[^0-9]/g, '');

    password.value = e.target.value;

};
const submitValue = () => {
    emit('submit', { name: userName.value, password: 123456 });
    toggleMenu();
}
</script>
<style>
.fab-button {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    border: none;
    font-size: 2rem;
    background-color: #4CAF50;
    color: white;
    border-radius: 50%;
    width: 3rem;
    height: 3rem;
    z-index: 9999;
}

.fab-container {
    position: fixed;
    top: 0;
    left: 0;

    .mask {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: -1;
    }
}

.fab-menu {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    background-color: white;

    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-color: white;
    border-style: solid;
    border-radius: 5px;
    padding: 1rem;

    .fab-menu-item {
        font-size: 1.3rem;

        input {

            width: 70vw;
            font-size: 1.5rem;
            margin: 0.5rem;
        }

        button {
            p {
                font-size: 1.5rem;
                padding-left: 15px;
                padding-right: 15px;
                padding-top: 7px;
                padding-bottom: 7px;
                color: white;
                word-spacing: 0.4em;
            }

            background-color:#4CAF50;
            border: none;
            border-radius: 40px;
            box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
        }
    }

}

/* 过渡动画 */

.fab-fade-leave-active {
    transition: opacity 0.3s ease-out;
}

.fab-fade-enter-active {
    transition: opacity 0.1s ease-in;
}

.fab-fade-enter-from {
    opacity: 0;
}

.fab-fade-leave-to {
    opacity: 0;
}
</style>